package com.zjf.controller;

import com.zjf.common.Result;
import com.zjf.entity.Orders;
import com.zjf.service.IOrdersService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/orders")
@CrossOrigin
public class OrdersController {
    @Resource
    private IOrdersService ordersService;


    @GetMapping("/getByoId")
    public Result<Orders> getOrdersById(@RequestParam("oId") Integer oId) {
        Orders orders= ordersService.getOrdersById(oId);
        return Result.success(orders,"查询订单成功") ;
    }

    @PostMapping("/add")
    public Result<Orders> addOrders(@RequestBody Orders orders){
        ordersService.createOrders(orders);
        return Result.success(orders,"新增订单成功");
    }

    @GetMapping("/pay")
    public Result<Integer> payOrder(@RequestParam("oId") Integer oId) throws Exception{
        int orderStatus =ordersService.payOrder(oId);
        return Result.success(orderStatus,"支付成功");
    }


    @GetMapping("/listByUId")
    public Result<List<Orders>> listOrdersByUserId(@RequestParam("uId") String uId){
        List<Orders> ordersList =ordersService.listOrdersByUserId(uId);
        return Result.success(ordersList,"查询订单成功");
    }






}
